clear
cd "C:\Users\brdblank\Dropbox\Alliances of Convenience\Manuscripts\Introducing AGCS\Replication Package_JCR"
cd "C:\Users\Brian\Dropbox\Alliances of Convenience\Manuscripts\Introducing AGCS\Replication Package_JCR"
cd "/Users/renanahmiles/Dropbox/Alliances of Convenience/Manuscripts/Introducing AGCS/Replication Package_JCR"
use ReplicationDataset.dta

***FIGURE 1***
graph pie regional_spending if region_cow != 6 & year==2000, over(region_cow) plabel(_all percent, size(*1.5) color(white)) plotregion(lstyle(none)) title("U.S. Spending by Region") note("Values are in billions of constant 2005 U.S. dollars.") graphregion(color(white))
graph pie regional_spending if region_cow != 6 & year==2005, over(region_cow) plabel(_all percent, size(*1.5) color(white)) plotregion(lstyle(none)) title("U.S. Spending by Region") note("Values are in billions of constant 2005 U.S. dollars.") graphregion(color(white))
graph pie regional_spending if region_cow != 6 & year==2010, over(region_cow) plabel(_all percent, size(*1.5) color(white)) plotregion(lstyle(none)) title("U.S. Spending by Region") note("Values are in billions of constant 2005 U.S. dollars.") graphregion(color(white))
graph pie regional_spending if region_cow != 6 & year==2015, over(region_cow) plabel(_all percent, size(*1.5) color(white)) plotregion(lstyle(none)) title("U.S. Spending by Region") note("Values are in billions of constant 2005 U.S. dollars.") graphregion(color(white))

***FIGURE A1***
*Note: the keep if country=="Japan" command is here to ensure that there is only one observation per year. "Japan" could be replaced by any country which has observations for all years 2000-2015
preserve
keep if country=="Japan"
tsset year
graph twoway line annual_spending year if year > 1999 & year < 2016 & country=="Japan", graphregion(color(white))
restore

***FIGURES A3 and A4
factor spend_pctgdp aid_pctgdp arms_pctgdp
rotate
predict support

***FIGURE A5***
preserve
keep if country=="Iraq"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2007, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Afghanistan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2007, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Djibouti"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2014, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Kyrgyz Republic"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Kazakhstan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Uzbekistan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Tajikistan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Pakistan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Turkmenistan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Georgia"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Armenia"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore
preserve
keep if country=="Azerbaijan"
tsset year
label var spending_policynoncomp_2005 "Noncompetitive spending ($)"
graph twoway line spending_policynoncomp_2005 year if year > 1999 & year < 2016, xline(2010, lpattern(dashed)) graphregion(color(white))
restore


xtset id year

***TABLE 1***
list annual_spending annual_noncomp_spending annual_policynoncomp_spending if year==2000
list annual_spending annual_noncomp_spending annual_policynoncomp_spending if year==2005
list annual_spending annual_noncomp_spending annual_policynoncomp_spending if year==2010
list annual_spending annual_noncomp_spending annual_policynoncomp_spending if year==2015

***TABLE 3***
sort country_spend
list country year country_spend us_ally
sort spending_pergdp
list country year spending_pergdp us_ally

***TABLE 4***
reg log_spend lag_gdp lag_gdppc lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust

***TABLE 5***
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop i.year, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop i.year, robust

***TABLE 6***
reg growth lag_growth lag_spend lag_gdp lag_gdppc lag_polity i.year i.region_cow, robust
reg growth lag_growth lag_spend lag_gdp lag_gdppc lag_polity i.year i.region_cow if civilwar_ucdp==1 | coin==1, robust
reg growth lag_growth lag_econaid lag_gdp lag_gdppc lag_polity i.year i.region_cow, robust
reg growth lag_growth lag_econaid lag_gdp lag_gdppc lag_polity i.year i.region_cow if civilwar_ucdp==1 | coin==1, robust
reg growth lag_growth lag_spend lag_econaid lag_gdp lag_gdppc lag_polity i.year i.region_cow, robust
reg growth lag_growth lag_spend lag_econaid lag_gdp lag_gdppc lag_polity i.year i.region_cow if civilwar_ucdp==1 | coin==1, robust

***TABLE 7***
reg unvotes lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg unvotes lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow lag_econaid, robust
reg unvotes lag_spend lag_gdp lag_gdppc lag_polity i.year i.id, robust
reg unvotes lag_spend lag_gdp lag_gdppc lag_polity i.year i.id lag_econaid, robust



***TABLE A1***
*ssc install sutex
*ssc install corrtex
sutex log_spend log_gdp log_gdppc polity civilwar_ucdp coin us_ally nonnatoally realprop_dum base unvotes if territory==., minmax nobs labels
sum log_spend log_gdp log_gdppc polity civilwar_ucdp coin us_ally nonnatoally realprop_dum base unvotes if territory==.

***TABLE A2***
corrtex log_spend lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_realprop, file("CorrMatrix.tex") sig replace
pwcorr log_spend lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_realprop

***TABLE A3***
corrtex log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_realprop lag_base if region_cow==3, file("CorrMatrix_Africa.tex") sig replace
pwcorr log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_realprop lag_base if region_cow==3

***TABLE A4***
reg log_spend_noncomp lag_gdp lag_gdppc lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop hnfirst, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop hnfirst i.year i.region_cow, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop hnfirst, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop hnfirst i.year i.region_cow, robust

***TABLE A5***
reg log_spend_noncomp lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop i.year, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop, robust
reg log_spend_noncomp lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop i.year, robust

***TABLE A6***
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop if year > 2006, robust
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base lag_realprop i.year if year > 2006, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop if year > 2006, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base lag_realprop i.year if year > 2006, robust

***TABLE A7***
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base_topcode_all lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base_topcode_all lag_realprop i.year, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base_topcode_all lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base_topcode_all lag_realprop i.year, robust

***TABLE A8***
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base_school lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_civilwar lag_base_school lag_realprop i.year, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base_school lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar lag_base_school lag_realprop i.year, robust

***TABLE A9***
reg unvotes lag_noncomp lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg unvotes lag_noncomp  lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow lag_econaid, robust
reg unvotes lag_noncomp  lag_gdp lag_gdppc lag_polity i.year i.id, robust
reg unvotes lag_noncomp lag_gdp lag_gdppc lag_polity i.year i.id lag_econaid, robust

***TABLE A10***
reg agree2un lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg agree2un lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow lag_econaid, robust
reg agree2un lag_spend lag_gdp lag_gdppc lag_polity i.year i.id, robust
reg agree2un lag_spend lag_gdp lag_gdppc lag_polity i.year i.id lag_econaid, robust

***TABLE A11***
reg absidealdiff lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg absidealdiff lag_spend lag_gdp lag_gdppc lag_polity coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow lag_econaid, robust
reg absidealdiff lag_spend lag_gdp lag_gdppc lag_polity i.year i.id, robust
reg absidealdiff lag_spend lag_gdp lag_gdppc lag_polity i.year i.id lag_econaid, robust

***TABLE A12***
preserve
fvset base 2002 year
reg log_spend lag_gdp lag_gdppc lag_democracy lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop, robust
reg log_spend lag_gdp lag_gdppc lag_democracy lag_civilwar lag_base lag_realprop i.year, robust
reg unvotes lag_spend lag_gdp lag_gdppc lag_democracy coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg growth lag_growth lag_spend lag_gdp lag_gdppc lag_democracy i.year i.region_cow, robust
restore

***TABLE A13***
reg log_spend lag_growth, robust
reg log_spend lag_growth i.region_cow i.year, robust
reg log_spend lag_growth lag_gdp lag_gdppc lag_polity i.region_cow i.year, robust
reg log_spend lag_growth lag_gdp lag_gdppc lag_democracy i.region_cow i.year, robust

***TABLE A14***
corrtex spend_pctgdp aid_pctgdp arms_pctgdp, file("Correlations_SpendAidArms_PctGDP.tex") digits(3) replace
pwcorr spend_pctgdp aid_pctgdp arms_pctgdp

***TABLE A15***
corrtex log_spend log_aid log_arms, file("Correlations_SpendAidArms_Log.tex") digits(3) replace
pwcorr log_spend log_aid log_arms

***TABLE A16***
reg log_spend lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg log_aid lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg log_arms lag_gdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg spend_pctgdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg aid_pctgdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust
reg arms_pctgdp lag_gdppc lag_polity lag_civilwar coin lag_us_ally lag_nonnatoally lag_realprop i.year i.region_cow, robust

***TABLE A17***
bys country: egen country_support = sum(support)
preserve
bys country: egen realprop_max = max(realprop_dum)
bys country: egen ally_max = max(us_ally)
bys country: egen nonnato_max = max(nonnato)
duplicates drop country, force
sort country_support
list country country_support ally_max nonnato_max realprop_max
restore
